package com.yh.wuye.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import android.content.Context;

public class PubFun
{
  /**
   * 退出程序(杀进程)
   * 
   * @param mAct
   */
  public static void killProcess(Context mAct)
  {
    String packageName = mAct.getPackageName();
    String processId = "";
    try
    {
      Runtime r = Runtime.getRuntime();
      Process p = r.exec("ps");
      BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String inline;
      while ((inline = br.readLine()) != null)
      {
        if (inline.contains(packageName))
        {
          break;
        }
      }
      br.close();
      StringTokenizer processInfoTokenizer = new StringTokenizer(inline);
      int count = 0;
      while (processInfoTokenizer.hasMoreTokens())
      {
        count++;
        processId = processInfoTokenizer.nextToken();
        if (count == 2)
        {
          break;
        }
      }
      r.exec("kill -15 " + processId);
    } catch (IOException ex)
    {
      System.exit(0);
    }
  }
}
